package com.hskn.hss.app.tlfacilities.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.elementtotal.vo.ElementsListByAppVo;
import com.hskn.hss.module.tlfacilities.mapper.TlFacilitiesMapper;
import com.hskn.hss.module.tlfacilities.service.ITlFacilitiesService;
import com.hskn.hss.module.tlfacilities.to.TIFacilitiesTo;
import com.hskn.hss.module.user.service.IUserService;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-13
 */
@Api(tags = {"-tl_facilities"}, description = "设施档案")
@Slf4j
@RestController
@RequestMapping("/hss/app/tlfacilities")
public class APPTlFacilitiesController {

    @Autowired
    ITlFacilitiesService tlFacilitiesService;
    @Resource
    private TlFacilitiesMapper tlFacilitiesMapper;
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(@RequestBody @Validated TIFacilitiesTo tiFacilitiesTo) {
        try {
            BaseEntity entity = new BaseEntity();
            return AjaxResult.success(tlFacilitiesService.getList(entity, tiFacilitiesTo));
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }


    /**
     * APP首页设施数据
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "appHomeFacilities", method = RequestMethod.POST)
    public AjaxResult<Object> appHomeFacilities(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            List<ElementsListByAppVo> json = tlFacilitiesService.appHomeFacilities(params);
            return AjaxResult.success(json);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("查询失败，请稍后再试");
        }
    }

}

